package DepartmentManagement

import (
	"MedicalTreatment/global"
	model "MedicalTreatment/model"
	"github.com/gin-gonic/gin"
)

func DepEdit(r *gin.Engine) {
	r.POST("/depEdit", func(context *gin.Context) {
		var dep model.Department
		if err := context.ShouldBindJSON(&dep); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
		} else {
			if err := global.DB.Model(&model.Department{}).Where("id = ?", dep.ID).Updates(model.Department{
				Name:    dep.Name,
				Address: dep.Address,
			}).Error; err != nil {
				context.JSON(200, gin.H{
					"Msg": "编辑失败",
				})
			} else {
				context.JSON(200, gin.H{
					"Msg": "更新成功",
				})
			}
		}
	})
}
